<div class="portlet light bordered">
	<div class="portlet-title">
        <div class="caption font-dark">
            <i class="fa fa-cog font-dark"></i>
            <span class="caption-subject bold">议价单管理 > 待审核议价单 > 审核</span>
        </div>
    </div>
    <div class="portlet-body form">
    <form role="form" action="/quotation/check" class="form-horizontal" method="post">
    <input type="hidden" id="id" name="id" value="$!item.id">
    <input type="hidden" id="quotationState" name="quotationState" value="PASS_QUOTATION">
    	<div class="portlet-title">
             <div class="caption font-dark">
                 <span class="caption-subject bold">基本信息</span>
             </div>
         </div>
         <div class="form-body left">
         	<div class="form-group">
                <label class="control-label col-md-2">议价单号：</label>
                <div class="control-label col-md-2" style="text-align:left">$!item.id</div>
                <label class="control-label col-md-2">售价总金额：</label>
                <div class="control-label col-md-2" style="text-align:left">$!item.quotationSkuPrice</div>
                <label class="control-label col-md-2">下单时间：</label>
                <div class="control-label col-md-2" style="text-align:left">$!item.timeString</div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-2">申请会员：</label>
                <div class="control-label col-md-2" style="text-align:left">$!userItem.id</div>
                <label class="control-label col-md-2">会员姓名：</label>
                <div class="control-label col-md-2" style="text-align:left">$!userItem.realname</div>
                <label class="control-label col-md-2">所属企业：</label>
                <div class="control-label col-md-2" style="text-align:left">$!companyItem.name</div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-2">会员来源：</label>
                <div class="control-label col-md-2" style="text-align:left">$!userItem.MemberSource</div>
                <label class="control-label col-md-2">议价单有效期：</label>
                <div class="col-md-2">
	                <input class="form-control common-time-datepicker-qn" type="text" id="ValidDate" name="ValidDate" value="$!item.ValidDateString" required readonly>
	            </div>
                <label class="control-label col-md-2">议价人：</label>
                <div class="control-label col-md-2" style="text-align:left">$!operatorUserName</div>
            </div>
            <div class="form-group">
            	#if($item.quotationState!='PASS_QUOTATION')
	                <label class="control-label col-md-2">未通过原因：</label>
	                <div class="col-md-6">
	                	<input type="text" class="form-control"  id="denyDetail" name="denyDetail" value="$!item.denyDetail">
	                </div>
                #end
                <label class="control-label col-md-2">议价时间：</label>
                <div class="control-label col-md-2" style="text-align:left">$!item.quotationTimeString</div>
            </div>
         </div>
         
         <div class="portlet-title">
             <div class="caption font-dark">
                 <span class="caption-subject bold">议价单货品</span>
             </div>
         </div>
         <div class="form-body left">
             <div class="form-group">
                 <div class="col-md-12">
                     <table class="table table-striped table-bordered table-hover">
                         <thead>
                         <tr>
                             <th width="3%">序号</th>
                             <th width="5%">货品编号</th>
                             <th width="12%">货品名称+规格</th>
                             <th width="5%">年采购量</th>
                             <th width="5%">售价</th>
                             <th width="3%" style="border-color: black;">议价</th>
                             
                             <th width="3%">序号</th>
                             <th width="5%">货品编号</th>
                             <th width="12%">货品名称+规格</th>
                             <th width="5%">年采购量</th>
                             <th width="5%">售价</th>
                             <th width="3%" style="border-color: black;">议价</th>
                             
                             <th width="3%">序号</th>
                             <th width="5%">货品编号</th>
                             <th width="12%">货品名称+规格</th>
                             <th width="5%">年采购量</th>
                             <th width="5%">售价</th>
                             <th width="3%"  style="border-color: black;">议价</th>
                         </tr>
                         </thead>
                         <tbody id="itemGroup">
                         <tr>
                         #foreach ($!item1 in $!pageQuotationItem.result)
                         #set($sku = $skuMap.get($item1))
                         #set($product = $productMap.get($item1))
                         	 #if($velocityCount > 1)
                         	 	#set($subCount = $velocityCount - 1)
                             	#set($modulo=$subCount % 3)
                             	#if($modulo == 0)
                             		</tr> <tr>
                             	#end
                         	 #end
                             <td>$!velocityCount</td>
                             <td>$!sku.code</td>
                             <td>$!product.name $!sku.attrAndAttrValues</td>
                             <td>$!item1.quantity</td>
                             <td class="skuPrice">$!sku.skuPrice</td>
                             <td>
                                 <input type="number" class="form-control input-small quotationPrice" step="0.01" skuPrice="$!sku.skuPrice"
                                 	id="quotationPrice_$!item1.id" name="quotationPrice_$!item1.id" value="$!item1.quotationPrice" min="0.01" 
                                 	onchange="javascript:changePrice(this,$!item1.id,$!item1.quotationPrice)" required>
                             </td>
                          #end
                          </tr>
                          <tr>
                          	<td colspan="15">
                          		市场售价总计：<span class="tQuotationSkuPrice">$!item.quotationSkuPrice</span>元  &nbsp;&nbsp; 
                          	  	议价单价总计：<span class="tQuotationPrice">$!item.quotationPrice</span>元 &nbsp;&nbsp; 
                          		差额总计：<span class="tDifference">$!tDifference</span>元
                          	</td>
                         </tr>
                         </tbody>
                     </table>
                 </div>
                 #set($page= $pageQuotationItem)
				 #set($pageUrl="/quotation/check?$!queryString&pageNo=")
				 #parse("_page.htm")
             </div>
         </div>
         
         <div class="form-actions right">
         		<input type="hidden" name="chkQuotationState" id="chkQuotationState" value="$item.quotationState" />
         		#if($item.quotationState=='BE_ON_QUOTATION')
				<a href="javascript:;" thref="/quotation/checkList" class="btn green ajax-post"><i class="fa fa-check"></i>提交</a>
				<a href="javascript:;" thref="/quotation/checkList" class="btn green"  onclick="javascript:deny(this);"><i class="fa fa-remove"></i>拒绝</a>
				#end
				<a href="/quotation/checkList" class="btn btn-outline grey-salsa ajaxify">返回</a>
         </div>
     </form>    
    </div>
</div>

<script src="/assets/scripts/views-date.js" type="text/javascript"></script>
<script type="text/javascript">
	function deny(obj){
		$("#denyDetail").attr("required", "true");
		$("#quotationState").val('DENY_QUOTATION');
		obj.classList.add('ajax-post');
	}

	function changePrice(obj,id,price){
		var quotationPrice = parseFloat(obj.value);
		if($('#chkQuotationState').val() == 'PASS_QUOTATION') {
			var oldprice = parseFloat(price).toFixed(2);
			toastr.warning('审核通过不可再修改！');
			obj.value = oldprice ;
			return ;
		}
		var formData = new FormData();
        formData.append("id", id);
        formData.append("quotationPrice", quotationPrice);
        
		$.ajax({
			url: "/quotationItem/edit",
			type: "POST",
			data: formData,
			contentType: false,
			processData: false,
			dataType: "json",
			success: function(res) {
				var skuPrice = parseFloat(obj.getAttribute('skuPrice'));
				if(quotationPrice < skuPrice){
					obj.style.setProperty('color', 'red');
					obj.style.setProperty('background', 'yellow');
				}else if(quotationPrice > skuPrice){
					obj.style.setProperty('color', 'green');
					obj.style.setProperty('background', 'yellow');
				}else{
					obj.style.setProperty('color', '');
					obj.style.setProperty('background', '');
				}
				
				var tQuotationPrice = res.data.tQuotationPrice;
				$(".tQuotationPrice").html(tQuotationPrice);
				var tDifference = res.data.tDifference;
				$(".tDifference").html(tDifference);
				
				var tQuotationSkuPrice = parseFloat($(".tQuotationSkuPrice").html());
				tQuotationPrice = parseFloat(tQuotationPrice);
				if(tQuotationPrice < tQuotationSkuPrice){
					$(".tDifference").css("color","red");
				}else if(tQuotationPrice > tQuotationSkuPrice){
					$(".tDifference").css("color","green");
				}else{
					$(".tDifference").css("color","");
				}
			}
		})
	}
	
	function init(){
		var productItem=$('#itemGroup tr');
		var skuPrice = 0;
		var quotationPrice = 0;
		
		for(var j=0; j<productItem.length; j++){
			for(var i=0;i<3;i++){
				skuPrice = parseFloat(productItem.eq(j).find('td.skuPrice').eq(i).html());
				quotationPrice = parseFloat(productItem.eq(j).find('input.quotationPrice').eq(i).val());
				if(quotationPrice < skuPrice){
					productItem.eq(j).find('input.quotationPrice').eq(i).css('color', 'red');
					productItem.eq(j).find('input.quotationPrice').eq(i).css('background', 'yellow');
				}else if(quotationPrice > skuPrice){
					productItem.eq(j).find('input.quotationPrice').eq(i).css('color', 'green');
					productItem.eq(j).find('input.quotationPrice').eq(i).css('background', 'yellow');
				}
			}
		}
		
		var tQuotationSkuPrice = parseFloat($(".tQuotationSkuPrice").html());
		var tQuotationPrice = parseFloat($(".tQuotationPrice").html());
		if(tQuotationPrice < tQuotationSkuPrice){
			$(".tDifference").css("color","red");
		}else if(tQuotationPrice > tQuotationSkuPrice){
			$(".tDifference").css("color","green");
		}else{
			$(".tDifference").css("color","");
		}
	}
	
	init();
	
	 $(".common-time-datepicker-qn").datetimepicker({
	     language:  "zh-CN",
	     isRTL: App.isRTL(),
	     autoclose: true,
	     format: "yyyy-mm-dd hh:ii:ss",
	     pickerPosition: (App.isRTL() ? "bottom-right" : "bottom-left"),
	     clearBtn:true,
	     todayBtn:false,
	     minuteStep:1
	 })
</script>
